import { createFileChunk } from "./createFile"
import { FileChunk, Message } from "./type"

onmessage = async (e) => {
  const { FILE, CHUNK_SIZE, start, end } = e.data as Message

  const tasks: Promise<FileChunk>[] = []
  for (let i = start; i < end; i++) {
    const chunk = createFileChunk(i, CHUNK_SIZE, FILE)
    tasks.push(chunk)
  }
  const chunks = await Promise.all(tasks)
  postMessage(chunks)
}
